﻿using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System.Collections.Generic;
using System.IO;

namespace MyORC
{
    class ExcelHelper
    {
        public static void CreateExcelFile(string FileName)
        {
            XSSFWorkbook workbook2007 = new XSSFWorkbook();
            workbook2007.CreateSheet("Sheet1");
            FileStream file2007 = new FileStream(FileName, FileMode.Create);
            workbook2007.Write(file2007);
            file2007.Close();
            workbook2007.Close();
        }

        public static void WriteXls(string newpath, int startRow, List<List<string>> dataList)
        {
            FileStream file2007 = new FileStream(newpath, FileMode.OpenOrCreate);
            XSSFWorkbook workbook2007 = new XSSFWorkbook();
            workbook2007.CreateSheet("Sheet1");
            XSSFSheet SheetOne = (XSSFSheet)workbook2007.GetSheet("Sheet1");
            for (int j = 0; j < dataList.Count; j++)
            {
                IRow row = SheetOne.CreateRow(startRow + j);
                for (int i = 0; i < dataList[0].Count; i++)
                {
                    string ss = dataList[j][i].ToString();
                    row.CreateCell(i).SetCellValue(dataList[j][i].ToString());
                }
            }
            workbook2007.Write(file2007);
            file2007.Close();
            workbook2007.Close();
        }
    }
}
